package com.tongren.framework.me.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.model.Response;
import com.tongren.framework.R;
import com.tongren.framework.callback.JsonCallback;
import com.tongren.framework.core.BaseActivity;
import com.tongren.framework.core.BaseListActivity;
import com.tongren.framework.core.CustomApplication;
import com.tongren.framework.model.BaseCourseTable;
import com.tongren.framework.model.BaseCourseware;
import com.tongren.framework.model.BasePageModel;
import com.tongren.framework.model.BaseResult;
import com.tongren.framework.model.BaseUser;
import com.tongren.framework.utils.DateHelper;
import com.tongren.framework.widgets.pull.BaseViewHolder;
import com.tongren.framework.widgets.pull.PullRecycler;

import java.util.ArrayList;

import static com.tongren.framework.constants.ConstantValues.BASE_URL;

/**
 * zhangxu
 */
public class CourseTalbeActivity extends BaseActivity {

    private int page = 1;
    private boolean isInitCache = false;
    private TextView tv_week1_1, tv_week1_2,tv_week1_3,tv_week1_4,tv_week1_5,tv_week1_6,tv_week1_7,tv_week1_8;
    private TextView tv_week2_1, tv_week2_2,tv_week2_3,tv_week2_4,tv_week2_5,tv_week2_6,tv_week2_7,tv_week2_8;
    private TextView tv_week3_1, tv_week3_2,tv_week3_3,tv_week3_4,tv_week3_5,tv_week3_6,tv_week3_7,tv_week3_8;
    private TextView tv_week4_1, tv_week4_2,tv_week4_3,tv_week4_4,tv_week4_5,tv_week4_6,tv_week4_7,tv_week4_8;
    private TextView tv_week5_1, tv_week5_2,tv_week5_3,tv_week5_4,tv_week5_5,tv_week5_6,tv_week5_7,tv_week5_8;

    @Override
    protected void setUpTitle(int titleResId) {
        super.setUpTitle(R.string.title_mycoursetable_activity);
    }

    @Override
    protected void setUpContentView() {
        setContentView(R.layout.activity_course_table,-1);
    }

    @Override
    protected void setUpView() {
        tv_week1_1 = (TextView) findViewById(R.id.tv_week1_1);
        tv_week1_2 = (TextView) findViewById(R.id.tv_week1_2);
        tv_week1_3 = (TextView) findViewById(R.id.tv_week1_3);
        tv_week1_4 = (TextView) findViewById(R.id.tv_week1_4);
        tv_week1_5 = (TextView) findViewById(R.id.tv_week1_5);
        tv_week1_6 = (TextView) findViewById(R.id.tv_week1_6);
        tv_week1_7 = (TextView) findViewById(R.id.tv_week1_7);
        tv_week1_8 = (TextView) findViewById(R.id.tv_week1_8);

        tv_week2_1 = (TextView) findViewById(R.id.tv_week2_1);
        tv_week2_2 = (TextView) findViewById(R.id.tv_week2_2);
        tv_week2_3 = (TextView) findViewById(R.id.tv_week2_3);
        tv_week2_4 = (TextView) findViewById(R.id.tv_week2_4);
        tv_week2_5 = (TextView) findViewById(R.id.tv_week2_5);
        tv_week2_6 = (TextView) findViewById(R.id.tv_week2_6);
        tv_week2_7 = (TextView) findViewById(R.id.tv_week2_7);
        tv_week2_8 = (TextView) findViewById(R.id.tv_week2_8);

        tv_week3_1 = (TextView) findViewById(R.id.tv_week3_1);
        tv_week3_2 = (TextView) findViewById(R.id.tv_week3_2);
        tv_week3_3 = (TextView) findViewById(R.id.tv_week3_3);
        tv_week3_4 = (TextView) findViewById(R.id.tv_week3_4);
        tv_week3_5 = (TextView) findViewById(R.id.tv_week3_5);
        tv_week3_6 = (TextView) findViewById(R.id.tv_week3_6);
        tv_week3_7 = (TextView) findViewById(R.id.tv_week3_7);
        tv_week3_8 = (TextView) findViewById(R.id.tv_week3_8);

        tv_week4_1 = (TextView) findViewById(R.id.tv_week4_1);
        tv_week4_2 = (TextView) findViewById(R.id.tv_week4_2);
        tv_week4_3 = (TextView) findViewById(R.id.tv_week4_3);
        tv_week4_4 = (TextView) findViewById(R.id.tv_week4_4);
        tv_week4_5 = (TextView) findViewById(R.id.tv_week4_5);
        tv_week4_6 = (TextView) findViewById(R.id.tv_week4_6);
        tv_week4_7 = (TextView) findViewById(R.id.tv_week4_7);
        tv_week4_8 = (TextView) findViewById(R.id.tv_week4_8);

        tv_week5_1 = (TextView) findViewById(R.id.tv_week5_1);
        tv_week5_2 = (TextView) findViewById(R.id.tv_week5_2);
        tv_week5_3 = (TextView) findViewById(R.id.tv_week5_3);
        tv_week5_4 = (TextView) findViewById(R.id.tv_week5_4);
        tv_week5_5 = (TextView) findViewById(R.id.tv_week5_5);
        tv_week5_6 = (TextView) findViewById(R.id.tv_week5_6);
        tv_week5_7 = (TextView) findViewById(R.id.tv_week5_7);
        tv_week5_8 = (TextView) findViewById(R.id.tv_week5_8);
    }

    @Override
    protected void setUpData(Bundle savedInstanceState) {

        BaseUser user = CustomApplication.getInstance().getUserModel();
        OkGo.<BaseResult<ArrayList<BaseCourseTable>>>post(BASE_URL+"findStudentCourseTable.ajax")//请求方式和请求url
                .tag(this)//请求的 tag, 主要用于取消对应的请求
                .params("clazzId", user.getClazzIdList().get(0).toString())//测试数据

                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)  //缓存模式先使用缓存,然后使用网络数据
                .execute(new JsonCallback<BaseResult<ArrayList<BaseCourseTable>>>() {
                    @Override
                    public void onSuccess(Response<BaseResult<ArrayList<BaseCourseTable>>> response) {
//                        handleResponse(response);
                        String str = response.toString();
                        System.out.println(str);
                        for (int i=0 ; i<response.body().result.size();i++){
                            BaseCourseTable bean = response.body().result.get(i);
                            String week = bean.getWeek();
                            String num = bean.getNum();
                            if ("1".equals(week)){
                                if ("1".equals(num)){ tv_week1_1.setText(bean.getTitle()); }
                                if ("2".equals(num)){ tv_week1_2.setText(bean.getTitle()); }
                                if ("3".equals(num)){ tv_week1_3.setText(bean.getTitle()); }
                                if ("4".equals(num)){ tv_week1_4.setText(bean.getTitle()); }
                                if ("5".equals(num)){ tv_week1_5.setText(bean.getTitle()); }
                                if ("6".equals(num)){ tv_week1_6.setText(bean.getTitle()); }
                                if ("7".equals(num)){ tv_week1_7.setText(bean.getTitle()); }
                                if ("8".equals(num)){ tv_week1_8.setText(bean.getTitle()); }
                            }

                            if ("2".equals(week)){
                                if ("1".equals(num)){ tv_week2_1.setText(bean.getTitle()); }
                                if ("2".equals(num)){ tv_week2_2.setText(bean.getTitle()); }
                                if ("3".equals(num)){ tv_week2_3.setText(bean.getTitle()); }
                                if ("4".equals(num)){ tv_week2_4.setText(bean.getTitle()); }
                                if ("5".equals(num)){ tv_week2_5.setText(bean.getTitle()); }
                                if ("6".equals(num)){ tv_week2_6.setText(bean.getTitle()); }
                                if ("7".equals(num)){ tv_week2_7.setText(bean.getTitle()); }
                                if ("8".equals(num)){ tv_week2_8.setText(bean.getTitle()); }
                            }

                            if ("3".equals(week)){
                                if ("1".equals(num)){ tv_week3_1.setText(bean.getTitle()); }
                                if ("2".equals(num)){ tv_week3_2.setText(bean.getTitle()); }
                                if ("3".equals(num)){ tv_week3_3.setText(bean.getTitle()); }
                                if ("4".equals(num)){ tv_week3_4.setText(bean.getTitle()); }
                                if ("5".equals(num)){ tv_week3_5.setText(bean.getTitle()); }
                                if ("6".equals(num)){ tv_week3_6.setText(bean.getTitle()); }
                                if ("7".equals(num)){ tv_week3_7.setText(bean.getTitle()); }
                                if ("8".equals(num)){ tv_week3_8.setText(bean.getTitle()); }
                            }

                            if ("4".equals(week)){
                                if ("1".equals(num)){ tv_week4_1.setText(bean.getTitle()); }
                                if ("2".equals(num)){ tv_week4_2.setText(bean.getTitle()); }
                                if ("3".equals(num)){ tv_week4_3.setText(bean.getTitle()); }
                                if ("4".equals(num)){ tv_week4_4.setText(bean.getTitle()); }
                                if ("5".equals(num)){ tv_week4_5.setText(bean.getTitle()); }
                                if ("6".equals(num)){ tv_week4_6.setText(bean.getTitle()); }
                                if ("7".equals(num)){ tv_week4_7.setText(bean.getTitle()); }
                                if ("8".equals(num)){ tv_week4_8.setText(bean.getTitle()); }
                            }

                            if ("5".equals(week)){
                                if ("1".equals(num)){ tv_week5_1.setText(bean.getTitle()); }
                                if ("2".equals(num)){ tv_week5_2.setText(bean.getTitle()); }
                                if ("3".equals(num)){ tv_week5_3.setText(bean.getTitle()); }
                                if ("4".equals(num)){ tv_week5_4.setText(bean.getTitle()); }
                                if ("5".equals(num)){ tv_week5_5.setText(bean.getTitle()); }
                                if ("6".equals(num)){ tv_week5_6.setText(bean.getTitle()); }
                                if ("7".equals(num)){ tv_week5_7.setText(bean.getTitle()); }
                                if ("8".equals(num)){ tv_week5_8.setText(bean.getTitle()); }
                            }
                        }


                    }

                    @Override
                    public void onCacheSuccess(Response<BaseResult<ArrayList<BaseCourseTable>>> response) {
                        //一般来说,只需呀第一次初始化界面的时候需要使用缓存刷新界面,以后不需要,所以用一个变量标识
                        if (!isInitCache) {
                            //一般来说,缓存回调成功和网络回调成功做的事情是一样的,所以这里直接回调onSuccess
                            onSuccess(response);
                            isInitCache = true;
                        }
                    }

                    @Override
                    public void onError(Response<BaseResult<ArrayList<BaseCourseTable>>> response) {
//                        handleError(response);
                    }
                });
    }







    class SampleViewHolder extends BaseViewHolder {

        ImageView iv_new_img;
        TextView tv_title;
        TextView tv_date;
//        TextView tv_state;

        public SampleViewHolder(View itemView) {
            super(itemView);
            tv_title = (TextView) itemView.findViewById(R.id.tv_new_title);
//            tv_date = (TextView) itemView.findViewById(R.id.tv_new_date);
//            tv_state = (TextView) itemView.findViewById(R.id.tv_state);
//            iv_new_img = (ImageView) itemView.findViewById(R.id.iv_new_img);
        }

        @Override
        public void onBindViewHolder(int position) {
//            Glide.with(iv_new_img.getContext())
//                    .load(mDataList.get(position).getPhoto())
//                    .centerCrop()
//                    .placeholder(R.color.app_primary_color)
//                    .crossFade()
//                    .into(iv_new_img);
//            tv_title.setText(mDataList.get(position).getDocumentName());
//            String date = DateHelper.timeStamp2Date(mDataList.get(position).getCreateDate(),"yyyy-MM-dd HH:mm");
//            tv_date.setText(date);
//            tv_state.setText(mDataList.get(position).getState());

        }

        @Override
        public void onItemClick(View view, int position) {
            Toast.makeText(CourseTalbeActivity.this, "dianji"+position, Toast.LENGTH_LONG).show();
        }

    }
}
